Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default subscription values when not specified #228

Merged

Conversation

mprahl
Copy link
Member

@mprahl mprahl commented Apr 11, 2024

This sets the default channel, source, and sourceNamespace when not provided in the policy.

Relates:
https://issues.redhat.com/browse/ACM-10561

Copy link
Member

@JustinKuli JustinKuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking clean overall!

controllers/operatorpolicy_controller.go Show resolved Hide resolved
controllers/operatorpolicy_controller.go Show resolved Hide resolved
Comment on lines 390 to 407
if (subSpec.CatalogSource != "" && subSpec.CatalogSource != catalog) ||
(subSpec.CatalogSourceNamespace != "" && subSpec.CatalogSourceNamespace != catalogNamespace) {
return errors.New(
"the subscription defaults could not be determined because the catalog doesn't match those in the " +
"PackageManifest",
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a minute, I was thinking that this kind of message could be good to surface regardless of defaulting. But I expect that the subscription would give some kind of error if the catalog doesn't match the package, so the user would still get a message there. Do you think that's right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that sounds right.

Comment on lines 393 to 394
"the subscription defaults could not be determined because the catalog doesn't match those in the " +
"PackageManifest",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"the subscription defaults could not be determined because the catalog doesn't match those in the " +
"PackageManifest",
"the subscription defaults could not be determined because the catalog specified in the " +
"policy does not match what was found in the PackageManifest on the cluster",

Especially if the user is not familiar with OLM, I think we should give some extra hints on where these values came from.

if err != nil {
if k8serrors.IsNotFound(err) {
return fmt.Errorf(
"%wthe subscription defaults could not be determined because the PackageManifest was not found",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I've seen wrapping a specific empty error like this. It's interesting. I'm still trying to find a way to do this kind of thing that I really like, did you find this somewhere else (just for reference)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this in the propagator with ErrRetryable but that comes from me, so I don't know of prior art doing this but I think it does the trick. I think the more "right" thing would be to have a custom error type as opposed to wrapping a custom error, but I didn't think it was worth the extra code.

Comment on lines 395 to 399
if catalog == "" || catalogNamespace == "" {
return fmt.Errorf(
"%wthe subscription defaults could not be determined because the PackageManifest didn't specify a catalog",
ErrPackageManifest,
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this one should wrap the error so it's retried - I think usually this would get fixed by the content in the catalog changing? What was your reasoning

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that this would ever occur, but I figured it was likely due to partial results being returned but it seems unlikely. I'll remove the retry.

Comment on lines 412 to 415
if defaultChannel == "" {
return fmt.Errorf(
"%wthe default channel could not be determined because the PackageManifest didn't specify one",
ErrPackageManifest,
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I'm not sure if this should be retried.

This sets the default channel, source, and sourceNamespace when not
provided in the policy.

Relates:
https://issues.redhat.com/browse/ACM-10561

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
Copy link
Member

@JustinKuli JustinKuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

openshift-ci bot commented Apr 15, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JustinKuli, mprahl

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit e71a482 into open-cluster-management-io:main Apr 15, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants